import dash
from dash import html
import feffery_utils_components as fuc
import feffery_antd_components as fac
from dash.dependencies import Input, Output

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        fac.AntdButton(
            '刷新页面',
            id='button-demo',
            type='primary'
        ),

        html.Div(
            id='refresh-message-demo'
        ),

        # 注入页面重载js脚本
        fuc.FefferyExecuteJs(
            id='refresh-js-demo'
        )
    ],
    style={
        'padding': '50px 100px'
    }
)


@app.callback(
    [Output('refresh-message-demo', 'children'),
     Output('refresh-js-demo', 'jsString')],
    Input('button-demo', 'nClicks')
)
def refresh_page(nClicks):
    if nClicks:
        return [
            [
                fac.AntdText('页面即将在'),
                fac.AntdText('3秒', strong=True),
                fac.AntdText('后刷新！')
            ],
            'setTimeout(() => window.location.reload(), 3000);'
        ]

    return dash.no_update


if __name__ == '__main__':
    app.run_server(debug=True)
